const path = require('path')
const defaultConfig = require('./src/config.ts')

const isProd = process.env.NODE_ENV === 'production'

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  pages: {
    index: {
      entry: 'src/entrys/Index/index.ts',
      filename: 'index.html',
      title: defaultConfig.title,
    },
    testMultipleEntry: {
      entry: 'src/entrys/TestMultipleEntry/index.ts',
      filename: 'testMultipleEntry.html',
      title: '多入口测试',
    },
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@$', resolve('src'))

    // 正式环境去除 console 输出
    isProd && config.optimization.minimizer('terser').tap(options => {
      // eslint-disable-next-line @typescript-eslint/camelcase
      options[0].terserOptions.compress.drop_console = true
      return options
    })
  },
  configureWebpack: {
    name: defaultConfig.title,
    resolve: {
      alias: {
        '@': resolve('src'),
      },
    },
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "@/styles/index.scss";',
      },
    },
  },
}
